<template>
  <div class="clock_main">
    <div class="help_top">
      <div class="help_title">
        <img src="./image/zaixian@2x.png" alt="">
        <div class="help_msg">
          <div class="msg_top">
            <p>张三</p>
            <p>
              <span ref="phone">2017.12.06</span>
            </p>
          </div>
          <div class="msg_bottom">
            <p>职位：绿植人员</p>
          </div>
        </div>
      </div>
    </div>
    <div class="line"></div>
    <div class="clock_title">
      <span>点击打卡记录你的时间和位置</span>
    </div>
    <div class="clock_list">
      <ol>
        <li class="first">
          <p>上班时间 09:00</p>
          <p>杭州是下城区 光阳国际351</p>
          <span class="before"></span><span class="after"></span>
        </li>
        <li>
          <p>午休时间 11:30</p>
          <p>杭州是下城区 光阳国际351</p>
          <span class="before"></span><span class="after"></span>
        </li>
        <li>
          <p>上班时间 13:00</p>
          <p>杭州是下城区 光阳国际351</p>
          <span class="before"></span><span class="after"></span>
        </li>
        <li>
          <p>下班时间 18:00</p>
          <p>杭州是下城区 光阳国际351</p>
          <span class="before"></span><span class="after"></span>
        </li>
      </ol>
    </div>
    <div class="btn_dc">
      <div class="ka" @click="daka()">
        <h2>{{message}}</h2>
        <p ref="mybox">{{time}}</p>
      </div>
    </div>
    <!--打卡成功的弹窗-->
    <mt-popup
      v-model="boxShow"
      popup-transition="popup-fade">
      <div class="clock_box">
        <div class="box_top">
          <div class="box_title">
            <img src="./image/xiantiao@2x.png" alt="">
            <span>打卡成功</span>
            <img src="./image/xiantiao@2x.png" alt="">
          </div>
          <div class="box_time">
            <span>时间：13:00</span>
          </div>
          <h4>地点</h4>
          <p>杭州市西湖区文三路90号
            东部软件园</p>
        </div>
        <div class="box_btn" @click="confirm()">
          <span>确定</span>
        </div>
      </div>
    </mt-popup>
  </div>
</template>
<style lang="scss">
  .clock_main {
    width: 100%;
    background: #fff;
    .help_top {
      width: 100%;
      .help_title {
        width: 100%;
        height: 65px;
        img {
          width: 44px;
          height: 44px;
          border-radius: 50%;
          float: left;
          margin-top: 10px;
          margin-left: 10px;
        }
        .help_msg {
          float: right;
          width: 83%;
          height: 65px;
          .msg_top {
            width: 100%;
            height: 25px;
            margin-top: 12px;
            p:first-child {
              float: left;
              font-size: 15px;
            }
            p:last-child {
              float: right;
              margin-right: 10px;
              span {
                font-size: 13px;
                float: right;
                /*line-height: 33px;*/
                color: #0078de;
              }
            }
          }
          .msg_bottom {
            width: 100%;
            height: 32px;
            p {
              float: left;
              line-height: 15px;
              font-size: 12px;
              color: #808080;
            }
          }
        }
      }
    }
    .line {
      width: 100%;
      height: 10px;
      background: #f2f2f2;
    }
    .clock_title {
      width: 100%;
      height: 33px;
      border-bottom: 1px solid #d7d7d7;
      span {
        color: #656666;
        line-height: 33px;
        margin-left: 10px;
        font-size: 13px;
      }
    }
    .clock_list {
      margin-top: 20px;
      ol {
        /*max-height: 300px;*/
        padding-left: 28px;
        padding-right: 20px;
        overflow: auto;
        /*height: 626px;*/
        li {
          position: relative;
          border-bottom: 1px solid #f5f5f5;
          margin-bottom: 30px;
          padding-bottom: 8px;
          color: #666;
          p {
            line-height: 25px;
          }
          .before {
            position: absolute;
            left: -13px;
            top: 2.2em;
            height: 82%;
            width: 0;
            border-left: 2px solid #ddd;
          }
          .after {
            position: absolute;
            left: -16px;
            top: 1.2em;
            width: 8px;
            height: 8px;
            background: #ddd;
            border-radius: 6px;
          }
        }
        .first {
          color: #0088cc;
          .after {
            background: #0088cc;
          }
        }
      }
    }
    .btn_dc {
      width: 100%;
      height: 200px;
      text-align: center;
      .ka {
        width: 127px;
        height: 127px;
        background: #0078de;
        display: inline-block;
        border-radius: 50%;
        h2 {
          font-size: 23px;
          color: #fff;
          margin-top:35px;
          font-weight: normal;
        }
        p {
          font-size: 15px;
          color: #fff;
        }
      }
    }
    .mint-popup {
      border-radius: 5px;
      /*width: 50%;*/
      .clock_box {
        width: 220px;
        height: 260px;
        border-radius: 5px;
        background: #fff;
        text-align: center;
        .box_top {
          width: 100%;
          height: 215px;
          .box_title {
            display: inline-flex;
            justify-content: space-around;
            align-items: center;
            padding-top: 20px;
            img:first-child {
              transform: rotateY(180deg);
              width: 25%;
              height: 2px;
            }
            img:last-child {
              width: 25%;
              height: 2px;
            }
            span {
              font-size: 26px;
              color: #0078de;
            }
          }
          .box_time {
            width: 124px;
            height: 30px;
            background: #0078de;
            border-radius: 15px;
            display: inline-block;
            margin-top: 20px;
            span {
              color: #fff;
              font-size: 15px;
              line-height: 30px;
            }
          }
          h4 {
            font-size: 17px;
            color: #292929;
            margin-top: 20px;
            margin-bottom: 20px;
          }
          p {
            font-size: 15px;
            color: #666;
            padding: 0 20px 0 20px;
            line-height: 20px;
          }
        }
        .box_btn {
          background: #0078de;
          height: 45px;
          border-bottom-left-radius: 5px;
          border-bottom-right-radius: 5px;
          text-align: center;
          span {
            font-size: 15px;
            color: #fff;
            line-height: 45px;
          }
        }
      }
    }
  }
</style>
<script>
  import headTop from '../../components/header/Header.vue'

  export default {
    name: 'Clocked',
    data () {
      return {
        time: '',
        data: '',
        message: '上班打卡',
        boxShow: false
//        sTime: '',
//        xTime: ''
      }
    },
    components: {
      headTop
    },
    created () {
      setInterval(this.updateTime, 1000)
      this.updateTime()
    },
    methods: {
      // 时间计算
      updateTime () {
        var cd = new Date()
        this.time = this.zeroPadding(cd.getHours(), 2) + ':' + this.zeroPadding(cd.getMinutes(), 2) + ':' + this.zeroPadding(cd.getSeconds(), 2)
      },
      // 数组0的添加
      zeroPadding (num, digit) {
        var zero = ''
        for (var i = 0; i < digit; i++) {
          zero += '0'
        }
        return (zero + num).slice(-digit)
      },
      daka () {
        this.boxShow = true
        if (this.message === '上班打卡') {
          this.message = '下班打卡'
          console.log('上班打卡' + this.$refs.mybox.innerHTML)
//          this.sTime = this.$refs.mybox.innerHTML
        } else {
          this.message = '上班打卡'
          console.log('下班打卡' + this.$refs.mybox.innerHTML)
//          this.xTime = this.$refs.mybox.innerHTML
        }
      },
      confirm () {
        this.boxShow = false
      }
    }
  }
</script>
